package com.kun.service_edu.controller;



import com.kun.service_edu.entity.EduCourse;
import com.kun.service_edu.entity.vo.CourseInfoVo;
import com.kun.service_edu.entity.vo.CoursePublishVo;
import com.kun.service_edu.service.EduCourseService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-10-04
 */
@RestController
@RequestMapping("/service_edu/edu-course")
@CrossOrigin
public class EduCourseController {
    @Autowired
    private EduCourseService courseService;
    //添加课程基本信息
    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody  CourseInfoVo courseInfoVo){
       String id =  courseService.addCourseInfo(courseInfoVo);
       return R.ok().data("courseId",id);
    }
    @PostMapping("getCourseInfoById/{courseId}")
    public R getCourseInfoById(@PathVariable String courseId){
      CourseInfoVo courseInfoVo=  courseService.getCourseInfo(courseId);
        return R.ok().data("courseInfo",courseInfoVo);
    }
    @PostMapping("updateCourseInfo")
    public R updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        courseService.updateCourseInfo(courseInfoVo);
        return R.ok();
    }

    @GetMapping("getPublishCourseInfo/{courseId}")
    public R getPublishCourseInfo(@PathVariable String courseId){
        CoursePublishVo  coursePublishVo= courseService.publishCourseInfo(courseId);
        return R.ok().data("courseInfoVo",coursePublishVo);
    }
    @PostMapping("publishCourse/{id}")
    public R publishCourse(@PathVariable String id){
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");
        courseService.updateById(eduCourse);
        return R.ok();
    }
    @PostMapping("getAllCourse/{current}/{limit}")
    public R getAllCourse(@PathVariable Long current,@PathVariable Long limit,@RequestBody(required = false) EduCourse eduCourse){
        List<EduCourse> list = courseService.getAllCourse(current,limit,eduCourse);
        return R.ok().data("list",list);
    }
    @PostMapping("delCourse/{courseId}")
    public R delCourse(@PathVariable String courseId){

        courseService.delCourse(courseId);
        return R.ok();
    }
}

